/* 
 * Copyright [2017] [Alex/LiBo(libo2dev.aliyun.com/alex.link@foxmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.bmsp.controller;

import java.lang.reflect.Field;

/**  
 * @Title BaseController.java  
 * @Package com.hyts.bmsp.controller  
 * @Description 基础操作控制器  
 * @author LiBo/Alex  
 * @date 2017年12月27日  
 * @version V1.0  
 */
public abstract class BaseController extends WebController {

	/**
	 * @Title: injectObj
	 * @Description: 注入对象操作
	 * @param t
	 * @return
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @return: T
	 */
	public <T> void injectRequestParamToObj(T t) throws IllegalArgumentException, IllegalAccessException{
		Field[] fields = t.getClass().getDeclaredFields();
		for(Field field:fields)
		{
			field.setAccessible(true);
			Object param = this.getParameter(field.getName());
			if(param != null)
			{
				switch(field.getType().toString()){
					case "class java.lang.String":
						 field.set(t,this.getParameter(field.getName(), ""));
						 break;
					case "class java.lang.Integer":
						 field.set(t,this.getParaToInt(field.getName()));
						 break;
					case "class java.lang.Boolean":
						 field.set(t,this.getParaToBoolean(field.getName()));
						 break;
					case "class java.lang.Long":
						 field.set(t,this.getParaToLong(field.getName()));
						 break;
					case "class java.util.Date":
						field.set(t,this.getParaToDate(field.getName()));
				}
			}
		}
	}
}
